package com.zhousb.deviceManager.controller;

import com.zhousb.deviceManager.common.R;
import com.zhousb.deviceManager.common.ResponseResult;
import com.zhousb.deviceManager.model.bo.RolePermissionBo;
import com.zhousb.deviceManager.model.entity.SysRole;
import com.zhousb.deviceManager.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhouShenBin
 * @date 2024/1/15 10:32
 * @description
 */
@RestController
@RequestMapping("/role")
@Tag(name = "角色管理")
public class SysRoleController {

    @Resource
    SysRoleService sysRoleService;
    @GetMapping("/list")
    @Operation(summary = "角色列表")
    public ResponseResult list(){
        return R.success(sysRoleService.list());
    }

    @PostMapping("/create")
    @Operation(summary = "新增角色")
    public ResponseResult create(@RequestBody SysRole sysRole){
        return R.success(sysRoleService.create(sysRole));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除角色")
    public ResponseResult delete(@RequestParam("id") String id){
        return R.success(sysRoleService.delete(Long.valueOf(id)));
    }

    @GetMapping("/list/permission")
    @Operation(summary = "获取角色已有菜单")
    public ResponseResult listPermission(@RequestParam("roleId")String roleId){
        return R.success(sysRoleService.listPermission(roleId));
    }

    @PostMapping("/permission")
    @Operation(summary = "授权菜单")
    public ResponseResult permission(@RequestBody RolePermissionBo bo){
        return R.success(sysRoleService.permission(bo));
    }
}
